package cn.scw.project.system.service.impl;

import cn.scw.common.utils.SecurityUtils;
import cn.scw.common.utils.bean.ToolUtils;
import cn.scw.project.system.domain.SysUserExpend;
import cn.scw.project.system.domain.netework.bean.SysUserExpendAddReq;
import cn.scw.project.system.domain.vo.SysUserExpendVo;
import cn.scw.project.system.mapper.SysUserExpendMapper;
import cn.scw.project.system.service.ISysUserExpendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户消费记录Service业务层处理
 *
 * @author api
 * @date 2020-05-20
 */
@Service
public class SysUserExpendServiceImpl implements ISysUserExpendService {
    @Autowired
    private SysUserExpendMapper sysUserExpendMapper;

    /**
     * 查询用户消费记录
     *
     * @param id 用户消费记录ID
     * @return 用户消费记录
     */
    @Override
    public SysUserExpend selectSysUserExpendById(Long id) {
        return sysUserExpendMapper.selectSysUserExpendById(id);
    }

    @Override
    public SysUserExpendVo selectSysUserExpendVoById(Long id) {
        return sysUserExpendMapper.selectSysUserExpendVoById(id);
    }

    /**
     * 查询用户消费记录列表
     *
     * @return 用户消费记录
     */
    @Override
    public List<SysUserExpendVo> selectSysUserExpendList(String type) {

        return sysUserExpendMapper.selectSysUserExpendList(SecurityUtils.getLoginUser().getUser().getUserId(),type);
    }

    /**
     * 新增用户消费记录
     *
     * @return 结果
     */
    @Override
    public SysUserExpend insertSysUserExpend(SysUserExpendAddReq req) {
        SysUserExpend expend=new SysUserExpend();
        ToolUtils.copyPropertiesIgnoreNull(req,expend);
        expend.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
         sysUserExpendMapper.insertSysUserExpend(expend);
         return expend;
    }

    /**
     * 修改用户消费记录
     *
     * @param sysUserExpend 用户消费记录
     * @return 结果
     */
    @Override
    public int updateSysUserExpend(SysUserExpend sysUserExpend) {
        return sysUserExpendMapper.updateSysUserExpend(sysUserExpend);
    }

    /**
     * 批量删除用户消费记录
     *
     * @param ids 需要删除的用户消费记录ID
     * @return 结果
     */
    @Override
    public int deleteSysUserExpendByIds(Long[] ids) {
        return sysUserExpendMapper.deleteSysUserExpendByIds(ids);
    }

    /**
     * 删除用户消费记录信息
     *
     * @param id 用户消费记录ID
     * @return 结果
     */
    @Override
    public int deleteSysUserExpendById(Long id) {
        return sysUserExpendMapper.deleteSysUserExpendById(id);
    }
}
